package com.grwx.omc.baselog.controller;

import com.grwx.omc.baselog.service.ILoginLogService;
import com.grwx.omc.common.entity.LoginLog;
import com.grwx.omc.common.entity.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Description: 用户登录的日志记录controller
 * @Author: ManJiang
 * @Date: 2020/5/11
 */
@RestController
@RequestMapping("/log")
public class LoginLogController {
    @Autowired
    private ILoginLogService loginLogService;

    /**
     * 登录日志的添加
     * @param loginLog
     * @return
     */
    @RequestMapping("/login_add")
    public int addLoginLog(@RequestBody LoginLog loginLog){
        return loginLogService.addLoginLog(loginLog);
    }

    /**
     * 登录日志的分页查询
     * @param map 分页参数.
     * @return
     */
    @RequestMapping("/login_pageList")
    public PageData<LoginLog> getLoginLogs(@RequestBody Map<String,Integer> map){
        Integer totalCount = loginLogService.getTotalCount();

        List<LoginLog> loginLogs = loginLogService.getLoginLogs(map);

        PageData<LoginLog> pageData = new PageData<LoginLog>(map.get("pageIndex"),map.get("pageSize"),totalCount,loginLogs);

        return pageData;
    }
}
